// pages/community-details/details.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    details:'',
    comment:'',
    replyshow:false,
    publishshow:false,
    focus:false,
    value:'',
    firstid:'',
    zan:'',
    fullScreenbtn:false
  },


  seebig: function (e) {
    var url = e.currentTarget.dataset.url
    console.log(e)
    var urls = []
    urls.push(url)
    wx.previewImage({
      current: url, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    });
  },


  // 论坛详情
  getdetails: function () {
    ajax('/api/index/forum_show', {
      data: {
        id:this.data.id,
        uqid: wx.getStorageSync("uqid")
      },
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      var arr = res.data
      var li1 = '.jpg', li2 = '.jpeg', li3 = '.png', li4 = '.gif';
      arr.plan_arrs=[]
      if(arr.plan){
        for(var a in arr.plan){
          if (arr.plan[a].includes(li1) || arr.plan[a].includes(li2) || arr.plan[a].includes(li3) || arr.plan[a].includes(li4)) {
            arr.plan_arrs[a] = { 'url': arr.plan[a], 'style': '0' }
          } else {
            arr.plan_arrs[a] = { 'url': arr.plan[a], 'style': '1' }
          }
        }
      }

      this.setData({
        details: res.data
      })
    })
  },
  // 评论列表
  getcomment: function () {
    ajax('/api/index/forum_show_comment', {
      data: {
        id: this.data.id,
        type:2,
        page:1,
        limit:20
      },
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {

      this.setData({
        comment: res.data
      })
    })
  },
  // 回复
  huifu:function(e){
    var firstid = e.currentTarget.dataset.firstid
    this.setData({
      replyshow:true,
      focus:true,
      firstid: firstid
    })
  },
  // 获取输入框内容
  inputvalue:function(e){
    this.setData({
      value: e.detail.value
    });
  },
  // 发表2级
  fabiao:function(){
    ajax('/api/user/comment_two_add', {
      data: {
        uqid: wx.getStorageSync("uqid"),
        id: this.data.firstid,
        content:this.data.value
      },
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      this.getcomment()
      this.setData({
        replyshow: false,
        focus: false,
        firstid: '',
        value:'',
      })
    })
  },
  // 说点啥
  shuosha:function(e){
    this.setData({
      publishshow: true,
      value: e.detail.value
    })
  },
  // 发表1级
  fabiaos:function(){
    ajax('/api/user/comment_first_add', {
      data: {
        uqid: wx.getStorageSync("uqid"),
        type:2,
        zid: this.data.id,
        content: this.data.value
      },
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      this.getcomment()
      this.setData({
        publishshow: false,
        focus: false,
        value: '',
      })
    })
  },
  // 点赞
  dianzan: function (e) {
    var id = e.currentTarget.dataset.id
    ajax('/api/user/love_add_or_del', {
      data: {
        uqid: wx.getStorageSync("uqid"),
        type: 2,
        zid: id
      },
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "PUT",
    }, res => {
      this.getdetails()
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id,
    })
    this.getdetails()
    this.getcomment()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})